package com.warehouse_management.purchase.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.warehouse_management.config.PageModel;
import com.warehouse_management.purchase.dao.ManufacturerDao;
import com.warehouse_management.purchase.model.Firm;
import com.warehouse_management.purchase.model.FirmCondition;
import com.warehouse_management.purchase.service.ManufacturerService;
import com.warehouse_management.system.model.City;
import com.warehouse_management.system.model.Province;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @PACKAGE_NAME: com.warehouse_management.purchase.service.impl
 * @NAME: ManufacturerServiceImpl
 * @USER: ZhouYongCheng
 * @DATE: 2022/10/3
 * @TIME: 2:54
 * @Description: 厂商管理服务层实现类
 */
@Service
public class ManufacturerServiceImpl extends ServiceImpl<ManufacturerDao, FirmCondition> implements ManufacturerService {
    @Autowired
    private ManufacturerDao manufacturerDao;

    @Override
    public PageModel<FirmCondition> PageFirmPosition(FirmCondition firm, PageModel<FirmCondition> pageModel) {
        pageModel.setPageNum(pageModel.getPageNum()==0?1: pageModel.getPageNum());
        pageModel.setPageSize(pageModel.getPageSize()==0?1: pageModel.getPageSize());

        PageHelper.startPage(pageModel.getPageNum(), pageModel.getPageSize());

        List<FirmCondition> firmList = manufacturerDao.queryFirmList();
        PageInfo<FirmCondition> pageInfo = new PageInfo<>(firmList);
        pageModel.setTotalPage(pageInfo.getPages());
        pageModel.setTotalRows(pageModel.getTotalPage());
        pageModel.setData(pageInfo.getList());


        return pageModel;
    }

    @Override
    public FirmCondition getOneFirm(FirmCondition firmCondition) {
        return manufacturerDao.queryOneFirm(firmCondition);
    }

    @Override
    public PageModel<FirmCondition> queryFirmListByCondition(FirmCondition firm, PageModel<FirmCondition> pageModel) {
        pageModel.setPageNum(pageModel.getPageNum()==0?1: pageModel.getPageNum());
        pageModel.setPageSize(pageModel.getPageSize()==0?1: pageModel.getPageSize());

        PageHelper.startPage(pageModel.getPageNum(), pageModel.getPageSize());

        List<FirmCondition> firmList = manufacturerDao.queryFirmListByCondition(firm);
        PageInfo<FirmCondition> pageInfo = new PageInfo<>(firmList);
        pageModel.setTotalPage(pageInfo.getPages());
        pageModel.setTotalRows(pageModel.getTotalPage());
        pageModel.setData(pageInfo.getList());
        return pageModel;
    }

    @Override
    public int addFirm(FirmCondition firm) {
        return manufacturerDao.addFirm(firm);
    }

    @Override
    public int updateFirm(FirmCondition firm) {
        return manufacturerDao.updateFirm(firm);
    }

    @Override
    public List<Province> queryProvince() {
        return manufacturerDao.queryProvince();
    }

    @Override
    public List<City> queryCity(String id) {
        return manufacturerDao.queryCity(id);
    }
}

